LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

--FF JK

ENTITY ic_5 IS

    PORT(clear, pin1, pin4, pin8, pin9, pin10, pin11, pin12, pin13 :IN STD_LOGIC; 
        pin2, pin3, pin5, pin6:OUT STD_LOGIC);

END ic_5;

ARCHITECTURE jkff_ic OF ic_5 IS

SIGNAL Q1, Q2: STD_LOGIC := '0';

BEGIN

    pin3 <= Q1;
    pin2 <= NOT Q1;
    pin5 <= Q2;
    pin6 <= NOT Q2;
	 
    PROCESS(pin12, pin13, clear)
    BEGIN
        IF(pin13 = '0' OR clear = '1') THEN
            Q1 <= '0';
        ELSIF(pin12 = '1' AND pin12'EVENT) THEN
            IF(pin1 = '1' AND pin4 = '0') THEN
                Q1 <= '1';
            ELSIF(pin1 = '0' AND pin4 = '1') THEN
                Q1 <= '0';
            ELSIF(pin1 = '1' AND pin4 = '1') THEN
                Q1 <= NOT Q1;
            ELSE
                Q1 <= Q1;
            END IF;
        ELSE
            Q1 <= Q1;
        END IF;
    END PROCESS;
	 
    PROCESS(pin9, pin10, clear)
    BEGIN
        IF(pin10 = '0' OR clear = '1') THEN
            Q2 <= '0';
        ELSIF(pin9 = '1' AND pin9'EVENT) THEN
            IF(pin8 = '1' AND pin11 = '0') THEN
                Q2 <= '1';
            ELSIF(pin8 = '0' AND pin11 = '1') THEN
                Q2 <= '0';
            ELSIF(pin8 = '1' AND pin11 = '1') THEN
                Q2 <= NOT Q2;
            ELSE
                Q2 <= Q2;
            END IF;
        ELSE
            Q2 <= Q2;
        END IF;
    END PROCESS;

END jkff_ic;

ARCHITECTURE jkffa_ic OF ic_5 IS

SIGNAL Q1, Q2: STD_LOGIC := '0';

BEGIN

    pin3 <= Q1;
    pin2 <= NOT Q1;
    pin5 <= Q2;
    pin6 <= NOT Q2;
	 
    PROCESS(pin12, pin13, clear)
    BEGIN
        IF(pin13 = '0' OR clear = '1') THEN
            Q1 <= '0';
        ELSIF(pin12 = '0' AND pin12'EVENT) THEN
            IF(pin1 = '1' AND pin4 = '0') THEN
                Q1 <= '1';
            ELSIF(pin1 = '0' AND pin4 = '1') THEN
                Q1 <= '0';
            ELSIF(pin1 = '1' AND pin4 = '1') THEN
                Q1 <= NOT Q1;
            ELSE
                Q1 <= Q1;
            END IF;
        ELSE
            Q1 <= Q1;
        END IF;
    END PROCESS;
	 
    PROCESS(pin9, pin10, clear)
    BEGIN
        IF(pin10 = '0' OR clear = '1') THEN
            Q2 <= '0';
        ELSIF(pin9 = '0' AND pin9'EVENT) THEN
            IF(pin8 = '1' AND pin11 = '0') THEN
                Q2 <= '1';
            ELSIF(pin8 = '0' AND pin11 = '1') THEN
                Q2 <= '0';
            ELSIF(pin8 = '1' AND pin11 = '1') THEN
                Q2 <= NOT Q2;
            ELSE
                Q2 <= Q2;
            END IF;
        ELSE
            Q2 <= Q2;
        END IF;
    END PROCESS;

END jkffa_ic;